apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ Name }}
spec:
  progressDeadlineSeconds: {{ RolloutTimeout }}
  replicas: {{ Replicas }}
  selector:
    matchLabels:
      name: {{ Name }}
  template:
    metadata:
      labels:
        name: {{ Name }}
    spec:
      containers:
      - name: {{ Name }}
        image: {{ Image }}
        {%- if Command %}
        command: {{ Command }}
        {%- endif %}
        resources:
          limits:
            cpu: {{ CpuRequest }}
            memory: {{ MemoryRequest }}
            ephemeral-storage: {{ EphemeralStorageRequest }}
            {%- if NvidiaGpuRequest %}
            nvidia.com/gpu: {{ NvidiaGpuRequest }}
            {%- endif %}
        # Added livenessProbe
        livenessProbe:
          exec:
            command:
            - /bin/true
          initialDelaySeconds: 5
          periodSeconds: 10
        # Added readinessProbe
        readinessProbe:
          exec:
            command:
            - /bin/true
          initialDelaySeconds: 5
          periodSeconds: 10
      nodeSelector:
        {%- for NodeSelector in NodeSelectors %}
        {{ NodeSelector }}
        {%- endfor %}
      terminationGracePeriodSeconds: 1
      # Add not-ready/unreachable tolerations for X seconds so that node
      # failure doesn't trigger pod deletion.
      tolerations:
      - key: "node.kubernetes.io/not-ready"
        operator: "Exists"
        effect: "NoExecute"
        tolerationSeconds: {{ PodTimeout }}
      - key: "node.kubernetes.io/unreachable"
        operator: "Exists"
        effect: "NoExecute"
        tolerationSeconds: {{ PodTimeout }}
      # Add topology spread constraints to fix an issue with Azure AKS where
      # admission webhook "validation.gatekeeper.sh" denied the request
      {%- if cloud == 'Azure' %}
      topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            name: {{ Name }}
      {%- endif %}
